package org.txazo.music.dao.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
import org.txazo.music.dao.FollowDao;

/**
 * 关注数据访问实现
 * 
 * @author Tu XiaoZhou
 * @since 2013-04-12
 */
@Repository("followDao")
public class FollowDaoImpl implements FollowDao {

	@Autowired
	private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

	public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
		return namedParameterJdbcTemplate;
	}

	public void setNamedParameterJdbcTemplate(
			NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
		this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
	}

	@Override
	public void addFollow(int id, int userId) {
		String sql = "insert into follow (fansId, userId, followTime) values (?, ?, ?)";
		namedParameterJdbcTemplate.getJdbcOperations().update(sql,
				new Object[] { id, userId, new Date() });
	}

	@Override
	public void removeFollow(int id, int userId) {
		String sql = "delete from follow where fansId = ? and userId = ?";
		namedParameterJdbcTemplate.getJdbcOperations().update(sql,
				new Object[] { id, userId });
	}

}
